package com.szhn.ossservice.controller;


import com.szhn.common.responsejson.R;
import com.szhn.ossservice.service.OssService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@CrossOrigin
@RestController
@RequestMapping("/ossservice/oss")
public class OssController {

    @Autowired
    private OssService ossService;

    @ApiOperation("上传文件，返回url地址")
    @PostMapping("upload")
    public R upload(MultipartFile file){
        String url = ossService.uploadFile(file);
        return R.ok().data("url",url);
    }

    @ApiOperation("删除文件")
    @DeleteMapping("delete/{url}")
    public R delete(@PathVariable String url){
        ossService.delete(url);
        return R.ok();
    }
}
